package deno4;
/*编写1个Shape类，具有属性：周长和面积；定义其子类三角形和矩形，
分别具有求周长的方法。定义主类E，在其main方法中创建三角形和矩形类的对象，
并赋给Shape类的对象a、b，使用对象a、b来测试其特性。
 */
abstract class Shape {
   public abstract void getarea();
   public abstract void getc();
}
class Triangle extends Shape{
    int sidelong;
    int height;

    public Triangle(int sidelong, int height) {
        this.sidelong = sidelong;
        this.height = height;
    }

    public void getarea(){
        System.out.println("三角形面积"+this.height * this.sidelong / 2.0);
    }
    public void getc(){
        System.out.println("三角形周长为"+sidelong * 3);
    }
}
class Rectangle extends Shape{
    int length;
    int width;

    public Rectangle(int length, int width) {
        this.length = length;
        this.width = width;
    }

    public void getarea(){
        System.out.println("矩形面积为"+this.length * this.width);
    }
    public void getc(){
        System.out.println("矩形周长为"+(this.width * 2 + this.length * 2));
    }
}
public class E {
    public static void method(Shape i){
        i.getc();
        i.getarea();
    }
    public static void main(String[] args) {
        Shape b=new Triangle(3,2);
        method(b);
        Shape a=new Rectangle(5,4);
        method(a);
    }
}


